package com.UnionPayCenter.controller;

import com.UnionPayCenter.entity.ResponseWrapper;
import com.UnionPayCenter.entity.ShopCardInfoEntity;
import com.UnionPayCenter.entity.ShopEntity;
import com.UnionPayCenter.entity.UserLevelEntity;
import com.UnionPayCenter.entity.vo.ShopInfoVo;
import com.UnionPayCenter.entity.vo.ShopLinkVo;
import com.UnionPayCenter.enums.ErrorCodeEnum;
import com.UnionPayCenter.exception.ApiException;
import com.UnionPayCenter.jwt.CurrentManager;
import com.UnionPayCenter.jwt.CurrentShop;
import com.UnionPayCenter.service.IShopService;
import com.UnionPayCenter.service.IWechatService;
import com.UnionPayCenter.shop.request.ShopUpdateRequest;
import com.UnionPayCenter.swagger.ApiJsonObject;
import com.UnionPayCenter.swagger.ApiJsonProperty;
import com.UnionPayCenter.util.Asserts;
import com.UnionPayCenter.util.StringUtils;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: UnionPayCenter
 * @description: 商铺
 * @author: bite
 * @create:
 **/
@Slf4j
@Api(value = "shop", tags = "商铺")
@RestController
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    private IShopService shopService;

    @Autowired
    private IWechatService wechatService;

    @CurrentManager
    @RequestMapping(value = "/findList", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]查询商铺列表", response = ShopEntity.class)
    public ResponseWrapper findList(
            @ApiJsonObject(name = "shopFindListParams", value = {
                    @ApiJsonProperty(key = "token", value = "token值")
            }) @RequestBody JSONObject jsonParam) {
        try {
            List<ShopEntity> list = shopService.findList(jsonParam);
            return ResponseWrapper.succeed(list);
        } catch (ApiException e) {
            log.error(String.format("[后台]查询商铺列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]查询商铺列表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentManager
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]创建网店", response = Integer.class)
    public ResponseWrapper create(
            @ApiJsonObject(name = "shopAddParams", value = {
                    @ApiJsonProperty(key = "token", value = "token值"),
                    @ApiJsonProperty(key = "type", value = "类型 0-美发"),
                    @ApiJsonProperty(key = "shopName", value = "名称"),
                    @ApiJsonProperty(key = "shopTel", value = "电话"),
                    @ApiJsonProperty(key = "shopAddress", value = "地址"),
                    @ApiJsonProperty(key = "shopDetailAddress", value = "详细地址")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer type = jsonParam.getInteger("type");
            if (type == null) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "类型"));
            }
            String name = jsonParam.getString("shopName");
            if (StringUtils.isNullStr(name)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "名称"));
            }
            String tel = jsonParam.getString("shopTel");
            if (StringUtils.isNullStr(tel)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "电话"));
            }
            String address = jsonParam.getString("shopAddress");
            if (StringUtils.isNullStr(address)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "地址"));
            }
            String detailAddress = jsonParam.getString("shopDetailAddress");
            if (StringUtils.isNullStr(detailAddress)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "详细地址"));
            }
            Integer id = shopService.create(jsonParam);
            return ResponseWrapper.succeed(id);
        } catch (ApiException e) {
            log.error(String.format("[后台]创建网店失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]创建网店失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentManager
    @CurrentShop
    @RequestMapping(value = "/findShop", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]查询商铺信息", response = ShopEntity.class)
    public ResponseWrapper findShop(
            @ApiJsonObject(name = "shopFindShopParams", value = {
                    @ApiJsonProperty(key = "token", value = "token值"),
                    @ApiJsonProperty(key = "shopId", value = "商铺id", type = "int")
            }) @RequestBody JSONObject jsonParam) {
        try {
            ShopEntity shop = shopService.findShop(jsonParam);
            return ResponseWrapper.succeed(shop);
        } catch (ApiException e) {
            log.error(String.format("[后台]查询商铺信息失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]查询商铺信息失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentShop
    @RequestMapping(value = "/getShop", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[前端]查询商家信息", response = ShopEntity.class)
    public ResponseWrapper getShop(
            @ApiJsonObject(name = "shopGetShopParams", value = {
                    @ApiJsonProperty(key = "shopId", value = "商铺id", type = "int")
            }) @RequestBody JSONObject jsonParam) {
        try {

            ShopEntity shop = shopService.getShop(jsonParam);
            return ResponseWrapper.succeed(shop);
        } catch (ApiException e) {
            log.error(String.format("[前端]查询商家信息失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[前端]查询商家信息失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentManager
    @CurrentShop
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]修改商铺信息", response = String.class)
    public ResponseWrapper update(
            @ApiJsonObject(name = "shopUpdateParams", value = {
                    @ApiJsonProperty(key = "token", value = "token值"),
                    @ApiJsonProperty(key = "shopId", value = "商铺id", type = "int"),
                    @ApiJsonProperty(key = "shopName", value = "名称"),
                    @ApiJsonProperty(key = "shopTel", value = "电话"),
                    @ApiJsonProperty(key = "shopAddress", value = "地址"),
                    @ApiJsonProperty(key = "shopDetailAddress", value = "详细地址")
            }) @RequestBody JSONObject jsonParam) {
        try {
            String name = jsonParam.getString("shopName");
            if (StringUtils.isNullStr(name)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "名称"));
            }
            String tel = jsonParam.getString("shopTel");
            if (StringUtils.isNullStr(tel)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "电话"));
            }
            String address = jsonParam.getString("shopAddress");
            if (StringUtils.isNullStr(address)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "地址"));
            }
            String detailAddress = jsonParam.getString("shopDetailAddress");
            if (StringUtils.isNullStr(detailAddress)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "详细地址"));
            }
            shopService.update(jsonParam);
            return ResponseWrapper.succeed("修改成功");
        } catch (ApiException e) {
            log.error(String.format("[后台]修改商铺信息失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]修改商铺信息失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentManager
    @CurrentShop
    @RequestMapping(value = "/findLink", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]商铺链接", response = ShopLinkVo.class)
    public ResponseWrapper findLink(
            @ApiJsonObject(name = "shopFindLinkParams", value = {
                    @ApiJsonProperty(key = "token", value = "token值"),
                    @ApiJsonProperty(key = "shopId", value = "商铺id", type = "int")
            }) @RequestBody JSONObject jsonParam) {
        try {
            ShopLinkVo vo = shopService.findLink(jsonParam);
            return ResponseWrapper.succeed(vo);
        } catch (ApiException e) {
            log.error(String.format("[后台]获取商铺链接失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取商铺链接失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentManager
    @CurrentShop
    @RequestMapping(value = "/findShopInfo", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]获取商铺配置信息", response = ShopInfoVo.class)
    public ResponseWrapper findShopInfo(
            @ApiJsonObject(name = "shopFindShopInfoParams", value = {
                    @ApiJsonProperty(key = "token", value = "token值"),
                    @ApiJsonProperty(key = "shopId", value = "商铺id", type = "int")
            }) @RequestBody JSONObject jsonParam) {
        try {
            ShopInfoVo vo = shopService.findShopInfo(jsonParam);
            return ResponseWrapper.succeed(vo);
        } catch (ApiException e) {
            log.error(String.format("[后台]获取商铺配置信息失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取商铺配置信息失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentShop
    @CurrentManager
    @RequestMapping(value = "/updateShopInfo", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]修改商铺配置信息", response = Integer.class)
    public ResponseWrapper updateShopInfo(@ApiParam(value = "修改商铺配置信息") @RequestBody ShopUpdateRequest shopUpdateRequest) {
//    public ResponseWrapper updateShopInfo(
//            @ApiJsonObject(name = "shopUpdateShopInfoParams", value = {
//                    @ApiJsonProperty(key = "token", value = "token值"),
//                    @ApiJsonProperty(key = "shopId", value = "商铺id"),
////                    @ApiJsonProperty(key = "appName", value = "小程序名称"),
//                    @ApiJsonProperty(key = "appId", value = "小程序appId"),
////                    @ApiJsonProperty(key = "appGhId", value = "小程序原始ID"),
//                    @ApiJsonProperty(key = "appSecret", value = "小程序秘钥"),
//                    @ApiJsonProperty(key = "bizMchId", value = "宇链商户号"),
//                    @ApiJsonProperty(key = "tid", value = "宇链tid"),
//                    //@ApiJsonProperty(key = "ylMerchant", value = "宇链商户号"),
//                    @ApiJsonProperty(key = "wechatId", value = "微信公众号appId"),
//                    @ApiJsonProperty(key = "wechatSecret", value = "微信公众号秘钥"),
////                    @ApiJsonProperty(key = "membercardId", value = "会员卡券ID", required = false),
//                    @ApiJsonProperty(key = "payChannel", value = "支付方式:1银联支付,2微信支付", type = "int")
//            }) @RequestBody JSONObject jsonParam) {
        try {
            shopService.updateShopInfo(shopUpdateRequest);
            return ResponseWrapper.succeed("修改成功");
        } catch (ApiException e) {
            log.error(String.format("[后台]修改商铺配置信息失败，参数:%s, 错误信息:%s", JSONObject.toJSONString(shopUpdateRequest), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]修改商铺配置信息失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentShop
    @CurrentManager
    @RequestMapping(value = "/download", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]获取小程序代码包", response = String.class)
    public ResponseWrapper download(
            @ApiJsonObject(name = "shopDownloadParams", value = {
                    @ApiJsonProperty(key = "token", value = "token值"),
                    @ApiJsonProperty(key = "shopId", value = "商铺id")
            }) @RequestBody JSONObject jsonParam) {
        try {
            String url = shopService.download(jsonParam);
            return ResponseWrapper.succeed(url);
        } catch (ApiException e) {
            log.error(String.format("[后台]获取小程序代码包失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取小程序代码包失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentShop
    @RequestMapping(value = "/getPayChannel", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[前端小程序]获取商铺支付方式(1银联支付,2微信支付)", response = Integer.class)
    public ResponseWrapper getPayChannel(
            @ApiJsonObject(name = "shopGetPayChannelParams", value = {
                    @ApiJsonProperty(key = "shopId", value = "商铺id")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer payChannel = shopService.getPayChannel(jsonParam);
            return ResponseWrapper.succeed(payChannel);
        } catch (ApiException e) {
            log.error(String.format("[前端小程序]获取商铺支付方式失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[前端小程序]获取商铺支付方式失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentShop
    @RequestMapping(value = "/getCardActivate", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[前端小程序]获取开卡组件参数", response = JSONObject.class)
    public ResponseWrapper getCardActivate(
            @ApiJsonObject(name = "shopGetCardActivateParams", value = {
                    @ApiJsonProperty(key = "shopId", value = "商铺id")
            }) @RequestBody JSONObject jsonParam) {
//        jsonParam.put("shopId",1);
        try {
            JSONObject json = shopService.getCardActivate(jsonParam);
            return ResponseWrapper.succeed(json);
        } catch (ApiException e) {
            log.error(String.format("[前端小程序]获取开卡组件参数失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[前端小程序]获取开卡组件参数失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentShop
    @RequestMapping(value = "/getCodeTypeList", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]获取Code展示类型列表", response = Map.class)
    public ResponseWrapper getCodeTypeList(
            @ApiJsonObject(name = "shopGetCodeTypeListParams", value = {
                    @ApiJsonProperty(key = "shopId", value = "商铺id")
            }) @RequestBody JSONObject jsonParam) {
        try {
            List<Map<String, String>> list = new ArrayList<>();
            Map<String, String> map = new HashMap<>();
            map.put("CODE_TYPE_TEXT", "文本");
            list.add(map);
            map = new HashMap<>();
            map.put("CODE_TYPE_BARCODE", "一维码");
            list.add(map);
            map = new HashMap<>();
            map.put("CODE_TYPE_QRCODE", "二维码");
            list.add(map);
            map = new HashMap<>();
            map.put("CODE_TYPE_ONLY_QRCODE", "仅显示二维码");
            list.add(map);
            map = new HashMap<>();
            map.put("CODE_TYPE_ONLY_BARCODE", "仅显示一维码 ");
            list.add(map);
            map = new HashMap<>();
            map.put("CODE_TYPE_NONE", "不显示任何码型");
            list.add(map);
            return ResponseWrapper.succeed(list);
        } catch (ApiException e) {
            log.error(String.format("[后台]获取Code展示类型列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取Code展示类型列表表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentShop
    @RequestMapping(value = "/getTimeLimitList", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]获取时间限制列表", response = Map.class)
    public ResponseWrapper getTimeLimitList(
            @ApiJsonObject(name = "shopGetTimeLimitListParams", value = {
                    @ApiJsonProperty(key = "shopId", value = "商铺id")
            }) @RequestBody JSONObject jsonParam) {
        try {
            List<Map<String, String>> list = new ArrayList<>();
            Map<String, String> map = new HashMap<>();
            map.put("MONDAY", "周一");
            list.add(map);
            map = new HashMap<>();
            map.put("TUESDAY", "周二");
            list.add(map);
            map = new HashMap<>();
            map.put("WEDNESDAY", "周三");
            list.add(map);
            map = new HashMap<>();
            map.put("THURSDAY", "周四");
            list.add(map);
            map = new HashMap<>();
            map.put("FRIDAY", "周五");
            list.add(map);
            map = new HashMap<>();
            map.put("SATURDAY", "周六");
            list.add(map);
            map = new HashMap<>();
            map.put("SUNDAY", "周日");
            list.add(map);
            return ResponseWrapper.succeed(list);
        } catch (ApiException e) {
            log.error(String.format("[后台]获取时间限制列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取时间限制列表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentShop
    @RequestMapping(value = "/getFormList", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]获取选项列表", response = Map.class)
    public ResponseWrapper getFormList(
            @ApiJsonObject(name = "shopGetFormListParams", value = {
                    @ApiJsonProperty(key = "shopId", value = "商铺id")
            }) @RequestBody JSONObject jsonParam) {
        try {
            List<Map<String, String>> list = new ArrayList<>();
            Map<String, String> map = new HashMap<>();
            map.put("USER_FORM_INFO_FLAG_MOBILE", "手机号");
            list.add(map);
            map = new HashMap<>();
            map.put("USER_FORM_INFO_FLAG_SEX", "性别");
            list.add(map);
            map = new HashMap<>();
            map.put("USER_FORM_INFO_FLAG_NAME", "姓名");
            list.add(map);
            map = new HashMap<>();
            map.put("USER_FORM_INFO_FLAG_BIRTHDAY", "生日");
            list.add(map);
            map = new HashMap<>();
            map.put("USER_FORM_INFO_FLAG_IDCARD", "身份证");
            list.add(map);
            map = new HashMap<>();
            map.put("USER_FORM_INFO_FLAG_EMAIL", "邮箱");
            list.add(map);
            map = new HashMap<>();
            map.put("USER_FORM_INFO_FLAG_LOCATION", "详细地址");
            list.add(map);
            map = new HashMap<>();
            map.put("USER_FORM_INFO_FLAG_EDUCATION_BACKGRO", "教育背景");
            list.add(map);
            map = new HashMap<>();
            map.put("USER_FORM_INFO_FLAG_INDUSTRY", "行业");
            list.add(map);
            map = new HashMap<>();
            map.put("USER_FORM_INFO_FLAG_INCOME", "收入");
            list.add(map);
            map = new HashMap<>();
            map.put("USER_FORM_INFO_FLAG_HABIT", "兴趣爱好");
            list.add(map);
            return ResponseWrapper.succeed(list);
        } catch (ApiException e) {
            log.error(String.format("[后台]获取选项列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取选项列表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentShop
    @RequestMapping(value = "/getColorList", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]获取颜色列表", response = Map.class)
    public ResponseWrapper getColorList(
            @ApiJsonObject(name = "shopGetColorListParams", value = {
                    @ApiJsonProperty(key = "shopId", value = "商铺id")
            }) @RequestBody JSONObject jsonParam) {
        try {
            List<Map<String, String>> list = new ArrayList<>();
            Map<String, String> map = new HashMap<>();
            map.put("Color010", "#63b359");
            list.add(map);
            map = new HashMap<>();
            map.put("Color020", "#2c9f67");
            list.add(map);
            map = new HashMap<>();
            map.put("Color030", "#509fc9");
            list.add(map);
            map = new HashMap<>();
            map.put("Color040", "#5885cf");
            list.add(map);
            map = new HashMap<>();
            map.put("Color050", "#9062c0");
            list.add(map);
            map = new HashMap<>();
            map.put("Color060", "#d09a45");
            list.add(map);
            map = new HashMap<>();
            map.put("Color070", "#e4b138");
            list.add(map);
            map = new HashMap<>();
            map.put("Color080", "#ee903c");
            list.add(map);
            map = new HashMap<>();
            map.put("Color081", "#f08500");
            list.add(map);
            map = new HashMap<>();
            map.put("Color082", "#a9d92d");
            list.add(map);
            map = new HashMap<>();
            map.put("Color090", "#dd6549");
            list.add(map);
            map = new HashMap<>();
            map.put("Color100", "#cc463d");
            list.add(map);
            map = new HashMap<>();
            map.put("Color101", "#cf3e36");
            list.add(map);
            map = new HashMap<>();
            map.put("Color102", "#5E6671");
            list.add(map);
            return ResponseWrapper.succeed(list);
        } catch (ApiException e) {
            log.error(String.format("[后台]获取颜色列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]获取颜色列表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentShop
    @CurrentManager
    @RequestMapping(value = "/getCardInfo", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]查询会员卡信息", response = ShopCardInfoEntity.class)
    public ResponseWrapper getCardInfo(
            @ApiJsonObject(name = "shopGetCardInfoParams", value = {
                    @ApiJsonProperty(key = "token", value = "token值"),
                    @ApiJsonProperty(key = "shopId", value = "商铺id"),
                    @ApiJsonProperty(key = "infoId", value = "会员卡id"),
            }) @RequestBody JSONObject jsonParam) {
        try {
            String infoId = jsonParam.getString("infoId");
            if (StringUtils.isNullStr(infoId)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "会员卡id"));
            }
            ShopCardInfoEntity card = shopService.getCardInfo(jsonParam);
            return ResponseWrapper.succeed(card);
        } catch (ApiException e) {
            log.error(String.format("[后台]查询会员卡信息失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]查询会员卡信息失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentShop
    @CurrentManager
    @RequestMapping(value = "/getCardList", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]查询会员卡列表", response = ShopCardInfoEntity.class)
    public ResponseWrapper getCardList(
            @ApiJsonObject(name = "shopGetCardListParams", value = {
                    @ApiJsonProperty(key = "token", value = "token值"),
                    @ApiJsonProperty(key = "shopId", value = "商铺id")
            }) @RequestBody JSONObject jsonParam) {
        try {
            PageInfo<ShopCardInfoEntity> list = shopService.getCardList(jsonParam);
            return ResponseWrapper.succeed(list);
        } catch (ApiException e) {
            log.error(String.format("[后台]查询会员卡列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]查询会员卡列表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentShop
    @CurrentManager
    @RequestMapping(value = "/createCard", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]添加会员卡", response = ShopCardInfoEntity.class)
    public ResponseWrapper createCard(
            @ApiJsonObject(name = "shopCreateCardParams", value = {
                    @ApiJsonProperty(key = "token", value = "token值"),
                    @ApiJsonProperty(key = "shopId", value = "商铺id"),
                    @ApiJsonProperty(key = "backgroundPicUrl", value = "否--商家自定义会员卡背景图", required = false),
                    @ApiJsonProperty(key = "codeType", value = "是--Code展示类型"),
                    @ApiJsonProperty(key = "prerogative", value = "是--会员卡特权说明,限制1024汉字"),
                    @ApiJsonProperty(key = "bonusRules", value = "否--积分规则", required = false),
                    @ApiJsonProperty(key = "balanceRules", value = "否--储值说明", required = false),
                    @ApiJsonProperty(key = "discount", value = "否--折扣", required = false),
                    @ApiJsonProperty(key = "logoUrl", value = "是--卡券的商户logo"),
                    @ApiJsonProperty(key = "brandName", value = "是--商户名字,字数上限为12个汉字"),
                    @ApiJsonProperty(key = "title", value = "是--卡券名，字数上限为9个汉字"),
                    @ApiJsonProperty(key = "color", value = "是--券颜色"),
                    @ApiJsonProperty(key = "notice", value = "是--卡券使用提醒，字数上限为16个汉字"),
                    @ApiJsonProperty(key = "description", value = "是--卡券使用说明，字数上限为1024个汉字"),
                    @ApiJsonProperty(key = "servicePhone", value = "否--客服电话", required = false),
                    @ApiJsonProperty(key = "centerTitle", value = "是--卡券中部居中的按钮9个汉字"),
                    @ApiJsonProperty(key = "centerSubTitle", value = "否--显示在入口下方的提示语12个汉字", required = false),
                    @ApiJsonProperty(key = "timeLimit", value = "否--时间限制/分割 如：MONDAY/TUESDAY/WEDNESDAY/THURSDAY/FRIDAY/SATURDAY/SUNDAY",
                            required = false),
                    @ApiJsonProperty(key = "requiredForm", value = "是--开卡必填项 /分割 如：USER_FORM_INFO_FLAG_MOBILE/USER_FORM_INFO_FLAG_NAME"),
                    @ApiJsonProperty(key = "optionalForm", value = "否--开卡选填项 /分割 如：USER_FORM_INFO_FLAG_IDCARD", required = false)
            }) @RequestBody JSONObject jsonParam) {
        try {
            String codeType = jsonParam.getString("codeType");
            if (StringUtils.isNullStr(codeType)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "Code展示类型"));
            }
            String prerogative = jsonParam.getString("prerogative");
            if (StringUtils.isNullStr(prerogative)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "会员卡特权说明"));
            }
            String logoUrl = jsonParam.getString("logoUrl");
            if (StringUtils.isNullStr(logoUrl)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "卡券的商户logo"));
            }
            String brandName = jsonParam.getString("brandName");
            if (StringUtils.isNullStr(brandName)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "商户名字"));
            }
            if (brandName.length() > 12) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW12.code(), String.format(ErrorCodeEnum.SW12.msg(), "商户名字限制12个汉字"));
            }
            String title = jsonParam.getString("title");
            if (StringUtils.isNullStr(title)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "卡券名"));
            }
            if (title.length() > 9) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW12.code(), String.format(ErrorCodeEnum.SW12.msg(), "卡券名限制9个汉字"));
            }
            String color = jsonParam.getString("color");
            if (StringUtils.isNullStr(color)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "券颜色"));
            }
            String notice = jsonParam.getString("notice");
            if (StringUtils.isNullStr(notice)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "卡券使用提醒"));
            }
            if (notice.length() > 16) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW12.code(), String.format(ErrorCodeEnum.SW12.msg(), "卡券使用提醒限制16个汉字"));
            }
            String description = jsonParam.getString("description");
            if (StringUtils.isNullStr(description)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "卡券使用说明"));
            }
            String centerTitle = jsonParam.getString("centerTitle");
            if (StringUtils.isNullStr(centerTitle)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "快速买单按钮"));
            }
            if (centerTitle.length() > 9) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW12.code(), String.format(ErrorCodeEnum.SW12.msg(), "快速买单按钮限制9个汉字"));
            }
            String centerSubTitle = jsonParam.getString("centerSubTitle");
            if (!StringUtils.isNullStr(centerSubTitle)) {
                if (centerSubTitle.length() > 12) {
                    return ResponseWrapper.failed(ErrorCodeEnum.SW12.code(), String.format(ErrorCodeEnum.SW12.msg(), "快速买单按钮提示语限制12个汉字"));
                }
            }
            String requiredForm = jsonParam.getString("requiredForm");
            if (StringUtils.isNullStr(requiredForm)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "开卡必填项"));
            }

            ShopCardInfoEntity card = shopService.createCard(jsonParam);
            return ResponseWrapper.succeed(card);
        } catch (ApiException e) {
            log.error(String.format("[后台]添加会员卡失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]添加会员卡失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @CurrentShop
    @CurrentManager
    @RequestMapping(value = "/updateCard", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]修改会员卡", response = ShopCardInfoEntity.class)
    public ResponseWrapper updateCard(
            @ApiJsonObject(name = "shopUpdateCardParams", value = {
                    @ApiJsonProperty(key = "token", value = "token值"),
                    @ApiJsonProperty(key = "shopId", value = "商铺id"),
                    @ApiJsonProperty(key = "infoId", value = "会员卡id"),
                    @ApiJsonProperty(key = "backgroundPicUrl", value = "否--商家自定义会员卡背景图", required = false),
                    @ApiJsonProperty(key = "codeType", value = "是--Code展示类型"),
                    @ApiJsonProperty(key = "prerogative", value = "是--会员卡特权说明,限制1024汉字"),
                    @ApiJsonProperty(key = "bonusRules", value = "否--积分规则", required = false),
                    @ApiJsonProperty(key = "balanceRules", value = "否--储值说明", required = false),
                    @ApiJsonProperty(key = "discount", value = "否--折扣", required = false),
                    @ApiJsonProperty(key = "logoUrl", value = "是--卡券的商户logo"),
//                    @ApiJsonProperty(key = "brandName", value = "是--商户名字,字数上限为12个汉字"),
                    @ApiJsonProperty(key = "title", value = "是--卡券名，字数上限为9个汉字"),
                    @ApiJsonProperty(key = "color", value = "是--券颜色"),
                    @ApiJsonProperty(key = "notice", value = "是--卡券使用提醒，字数上限为16个汉字"),
                    @ApiJsonProperty(key = "description", value = "是--卡券使用说明，字数上限为1024个汉字"),
                    @ApiJsonProperty(key = "servicePhone", value = "否--客服电话", required = false),
                    @ApiJsonProperty(key = "centerTitle", value = "是--卡券中部居中的按钮"),
                    @ApiJsonProperty(key = "centerSubTitle", value = "否--显示在入口下方的提示语", required = false),
                    @ApiJsonProperty(key = "timeLimit", value = "否--时间限制/分割 如：MONDAY/TUESDAY/WEDNESDAY/THURSDAY/FRIDAY/SATURDAY/SUNDAY",
                            required = false),
                    @ApiJsonProperty(key = "requiredForm", value = "是--开卡必填项 /分割 如：USER_FORM_INFO_FLAG_MOBILE/USER_FORM_INFO_FLAG_NAME"),
                    @ApiJsonProperty(key = "optionalForm", value = "否--开卡选填项 /分割 如：USER_FORM_INFO_FLAG_IDCARD", required = false)
            }) @RequestBody JSONObject jsonParam) {
        try {
            String codeType = jsonParam.getString("codeType");
            if (StringUtils.isNullStr(codeType)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "Code展示类型"));
            }
            String prerogative = jsonParam.getString("prerogative");
            if (StringUtils.isNullStr(prerogative)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "会员卡特权说明"));
            }
            String logoUrl = jsonParam.getString("logoUrl");
            if (StringUtils.isNullStr(logoUrl)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "卡券的商户logo"));
            }
//            String brandName = jsonParam.getString("brandName");
//            if (StringUtils.isNullStr(brandName)) {
//                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "商户名字"));
//            }
            String title = jsonParam.getString("title");
            if (StringUtils.isNullStr(title)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "卡券名"));
            }
            if (title.length() > 9) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW12.code(), String.format(ErrorCodeEnum.SW12.msg(), "卡券名限制9个汉字"));
            }
            String color = jsonParam.getString("color");
            if (StringUtils.isNullStr(color)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "券颜色"));
            }
            String notice = jsonParam.getString("notice");
            if (StringUtils.isNullStr(notice)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "卡券使用提醒"));
            }
            if (notice.length() > 16) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW12.code(), String.format(ErrorCodeEnum.SW12.msg(), "卡券使用提醒限制16个汉字"));
            }
            String description = jsonParam.getString("description");
            if (StringUtils.isNullStr(description)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "卡券使用说明"));
            }
            String centerTitle = jsonParam.getString("centerTitle");
            if (StringUtils.isNullStr(centerTitle)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "卡券中部居中的按钮"));
            }
            if (centerTitle.length() > 9) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW12.code(), String.format(ErrorCodeEnum.SW12.msg(), "快速买单按钮限制9个汉字"));
            }
            String centerSubTitle = jsonParam.getString("centerSubTitle");
            if (!StringUtils.isNullStr(centerSubTitle)) {
                if (centerSubTitle.length() > 12) {
                    return ResponseWrapper.failed(ErrorCodeEnum.SW12.code(), String.format(ErrorCodeEnum.SW12.msg(), "快速买单按钮提示语限制12个汉字"));
                }
            }
            String requiredForm = jsonParam.getString("requiredForm");
            if (StringUtils.isNullStr(requiredForm)) {
                return ResponseWrapper.failed(ErrorCodeEnum.SW11.code(), String.format(ErrorCodeEnum.SW11.msg(), "开卡必填项"));
            }

            ShopCardInfoEntity card = shopService.updateCard(jsonParam);
            return ResponseWrapper.succeed(card);
        } catch (ApiException e) {
            log.error(String.format("[后台]修改会员卡失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]修改会员卡失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/uploadPic", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[后台]微信图片/素材上传", response = String.class)
    public ResponseWrapper uploadImg(@RequestParam(value = "shopId") Integer shopId, @RequestParam(value = "file") MultipartFile file) {
        try {
            String url = wechatService.uploadImg(shopId, file);
            return ResponseWrapper.succeed(url);
        } catch (ApiException e) {
            log.error(String.format("[后台]微信图片/素材上传失败，错误信息:%s", e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[后台]微信图片/素材上传失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }


    @RequestMapping(value = "/getShopInitialMemberLevel", method = RequestMethod.POST)
    @ApiOperation(tags = "商铺", httpMethod = "POST", value = "[小程序]获取店铺初始会员等级", response = UserLevelEntity.class)
    public ResponseWrapper getShopInitialMemberLevel(@ApiParam("店铺Id") @RequestParam(value = "shopId", required = false) Integer shopId) {
        Asserts.notNull(shopId, "店铺Id");
        return ResponseWrapper.succeed(shopService.getShopInitialMemberLevel(shopId));
    }
}
